import QtQuick 2.4
import Qt.labs.controls 1.0
import QtQml.Models 2.2
import QtQuick.Layouts 1.1

import "../js/MyInfoNavigator.qml.js" as Jit
import "../template" as Tm

Tm.Navigator {
    id: nav
    title: "个人资料"
    Flickable {
        id: flickable
        anchors.fill: parent
        contentWidth: parent.width
        contentHeight:720

        ScrollIndicator.vertical: ScrollIndicator { }
        Pane {
     anchors.fill: parent
            ColumnLayout {
                anchors.fill: parent

                Pane {
                    Layout.fillWidth: true

                    Layout.preferredHeight: 210

                    RowLayout {
                        anchors.centerIn: parent
                        anchors.horizontalCenterOffset: -24
                        ToolButton {
                            id: btn
                            Item {
                                id: imageItem
                                property url fileUrl: ""
                                onFileUrlChanged: {
                                    Jit.commitResult(fileUrl)
                                }
                            }

                            label: Image {
                                id: image
                                anchors.centerIn: parent
                                source:  usinfo.image
                                onStatusChanged: {
                                    if (image.status == Image.Null || image.status == Image.Error)  {
                                        image.source ="../images/image_header.png"

                                    }
                                }
                            }

                            onClicked:  Jit.goImage()
                        }
                        ColumnLayout {
                            Label {
                                text: usinfo.name
                            }

                            Label {
                                text: usinfo.mobile
                            }
                        }
                    }
                }



                Pane {
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    ToolButton {
                        anchors.right: parent.right
                        anchors.rightMargin: 9
                        label:
                            Image {
                            anchors.centerIn: parent
                            source:  gridLayout.readonlyMode ?"../images/pencil.png"  : "../images/pencil-ok.png"

                        }

                        onClicked:  Jit.saveInfo()
                    }
                    GridLayout {
                        id: gridLayout
                        anchors.horizontalCenter: parent.horizontalCenter
                        columns: 2
                        property bool readonlyMode: true

                        Label {
                            text: "姓名"
                        }
                        TextField {
                            id: txtNick
                            text: usinfo.name
                            readOnly: gridLayout.readonlyMode
                        }

                        Label {
                            text: "手机"
                        }
                        TextField {
                            id: txtMobile
                            text: usinfo.mobile
                            readOnly: gridLayout.readonlyMode
                        }
                        Label {
                            text: "邮箱"

                        }
                        TextField {
                            id: txtMail
                            text: usinfo.mail
                            readOnly: true
                        }
                        Label {
                            text: "身份证"
                        }
                        TextField {
                            id: txtId
                            text: usinfo.identity

                            readOnly: true
                        }
                        Label {
                            text: "教练"
                            visible: usinfo.role == "s"
                        }
                        TextField {
                            text: usinfo.parent.display

                            visible: usinfo.role == "s"
                            readOnly: true
                        }

                        Label {
                            text: "学校"
                        }
                        TextField {
                            text: usinfo.school.display
                            readOnly: true
                        }

                        Label {
                            text: "身份"
                        }
                        TextField {
                            text: usinfo.displayRole
                            readOnly: true
                        }

                        Label {
                            text: "地址"
                        }
                        TextField {
                            id: txtAddress
                            text: usinfo.address
                            readOnly: gridLayout.readonlyMode
                        }
                    }
                }
            }
        }
    }
}

